package com.guodl.controller;

import com.guodl.domain.User;
import com.guodl.service.UserService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/user")
public class UserController {
    
    // 该UserService通过rpc调用得到
    @Autowired
    private UserService userService;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/getUserInfo")
    public User getUserInfo() {
        System.out.println("远程调用了 /user/getUserInfo 接口");
        User user = userService.getUserInfo();
        System.out.println("调用返回结果:" + user);

        HashMap<String, String> map = new HashMap<String, String>();
        map.put("id", "1");
        map.put("name", "测试");
        //根据key发送到对应的队列
        rabbitTemplate.convertAndSend("queuekey", user);
        rabbitTemplate.convertAndSend("queuekey", map);
      

        return user;
    }
}
